package datasource

import (
	"api-gateway-core/common"
	"api-gateway-core/datasource/connection"
	"api-gateway-core/mapping"
	"errors"
	"fmt"
)

type DataSourceType string

const (
	// 定义HttpCommandType的各个可能值
	DUBBO DataSourceType = "DUBBO"
	HTTP  DataSourceType = "HTTP"
)

type Datasource struct {
	Configuration  *common.Configuration
	DataSourceType DataSourceType
	HttpStatement  *mapping.HttpStatement
	InfoMap        map[string]any
}

func (this *Datasource) GetConnection() (Connection, error) {
	switch this.DataSourceType {
	case HTTP:
		//TODO 暂时不需要实现
		return connection.NewHttpConnection(this.HttpStatement, this.InfoMap)
	case DUBBO:
		return connection.NewDubboConnection(this.Configuration, this.HttpStatement)
	default:
		return nil, errors.New(fmt.Sprintf("DataSourceType：%s没有对应的数据源实现", this.DataSourceType))
	}
	//return nil, errors.New(fmt.Sprintf("DataSourceType：%s没有对应的数据源实现", this.DataSourceType))
}
